--SELECT * FROM lion_tag
--DELETE FROM lion_tag
INSERT INTO lion_tag
SELECT
newid() AS [Id],[tag] AS [TagName],count(companyid) AS [Candidates],case len(convert(varchar(10),companyid))
    when 5 then '00000000-0000-0000-0000-0000000' + convert(varchar(10),companyid) 
    when 4 then '00000000-0000-0000-0000-00000000' + convert(varchar(10),companyid) 
    when 3 then '00000000-0000-0000-0000-000000000' + convert(varchar(10),companyid) 
    when 2 then '00000000-0000-0000-0000-0000000000' + convert(varchar(10),companyid) 
    when 1 then '00000000-0000-0000-0000-00000000000'+ convert(varchar(10),companyid) 
    end AS [CompanyId]
from srv_lnk.nchr2008.dbo.resumescore where not tag is null and len(tag)>=1
group by companyid,tag
order by companyid

